package wuxianshua.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import wuxianshua.dao.ScoreMapper;
import wuxianshua.pojo.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description:
 * Datetime:    2021/3/23   19:48
 * Author:   jianglei
 */
@Service
public class ScoreService {

    @Autowired
    private ScoreMapper scoreMapper;

    public Map getPerformance(){
        Map resMap = new HashMap();
        List<Score> allItem = scoreMapper.getAll();
        List<String > dataLsit = new ArrayList<>();

        List<PerformanceSeries> seriesList = new ArrayList<>();
        ArrayList <Float>timeData = new ArrayList<>();
        ArrayList <Float>sizeData = new ArrayList<>();
        allItem.forEach(score -> {
            dataLsit.add(score.getName());
            timeData.add(score.getTimes());
            sizeData.add(score.getPth());
        });
        PerformanceSeries timePerformanceSeries = new PerformanceSeries("检测运行时间(task/s)",timeData);
        PerformanceSeries sizePerformanceSeries = new PerformanceSeries("模型大小(100M)",sizeData);

        seriesList.add(timePerformanceSeries);
        seriesList.add(sizePerformanceSeries);

        resMap.put("series",seriesList);
        resMap.put("data",dataLsit);
        return resMap;
    }


    public Map getScoreByProtoType(String protoType){
        String sqlProtoType = "%"+protoType+"%";
        Map resMap = new HashMap();
        List<Score> scoreByTimes = scoreMapper.getScoreByProtoType(sqlProtoType);
        List<String > legendLsit = new ArrayList<>();
        List<Series> seriesList = new ArrayList<>();
        scoreByTimes.forEach(score -> {
            legendLsit.add(score.getName());
            Series series = new Series();
            series.setName(score.getName());
            Map<String, String> emphasis = new HashMap<>();
            emphasis.put("focus","series");
            series.setEmphasis(emphasis);
            ArrayList<Float> integers = new ArrayList<>();
            integers.add(score.getAp1());
            integers.add(score.getAp2());
            integers.add(score.getAp3());
            integers.add(score.getAp4());
            integers.add(score.getAp5());
            integers.add(score.getAp6());
            integers.add(score.getAr1());
            integers.add(score.getAr2());
            integers.add(score.getAr3());
            integers.add(score.getAr4());
            integers.add(score.getAr5());
            integers.add(score.getAr6());
            series.setData(integers);
            seriesList.add(series);
        });
        resMap.put("series",seriesList);
        resMap.put("legend",legendLsit);

        return resMap;
    }


    public Map getScoreByAdvance(String advance){
        Map resMap = new HashMap();
        String sqlAdvance = "%"+advance+"%";
        List<Score> scoreByTimes = scoreMapper.getScoreByAdvance(sqlAdvance);
        List<String > legendLsit = new ArrayList<>();
        List<Series> seriesList = new ArrayList<>();
        scoreByTimes.forEach(score -> {
            legendLsit.add(score.getName());
            Series series = new Series();
            series.setName(score.getName());
            Map<String, String> emphasis = new HashMap<>();
            emphasis.put("focus","series");
            series.setEmphasis(emphasis);
            ArrayList<Float> integers = new ArrayList<>();
            integers.add(score.getAp1());
            integers.add(score.getAp2());
            integers.add(score.getAp3());
            integers.add(score.getAp4());
            integers.add(score.getAp5());
            integers.add(score.getAp6());
            integers.add(score.getAr1());
            integers.add(score.getAr2());
            integers.add(score.getAr3());
            integers.add(score.getAr4());
            integers.add(score.getAr5());
            integers.add(score.getAr6());
            series.setData(integers);
            seriesList.add(series);
        });
        resMap.put("series",seriesList);
        resMap.put("legend",legendLsit);

        return resMap;
    }

    public Map getScoreByOrign(){
        Map resMap = new HashMap();
        List<Score> scoreByTimes = scoreMapper.getScoreByOrign();
        List<String > legendLsit = new ArrayList<>();
        List<Series> seriesList = new ArrayList<>();
        scoreByTimes.forEach(score -> {
            legendLsit.add(score.getName());
            Series series = new Series();
            series.setName(score.getName());
            Map<String, String> emphasis = new HashMap<>();
            emphasis.put("focus","series");
            series.setEmphasis(emphasis);
            ArrayList<Float> integers = new ArrayList<>();
            integers.add(score.getAp1());
            integers.add(score.getAp2());
            integers.add(score.getAp3());
            integers.add(score.getAp4());
            integers.add(score.getAp5());
            integers.add(score.getAp6());
            integers.add(score.getAr1());
            integers.add(score.getAr2());
            integers.add(score.getAr3());
            integers.add(score.getAr4());
            integers.add(score.getAr5());
            integers.add(score.getAr6());
            series.setData(integers);
            seriesList.add(series);
        });
        resMap.put("series",seriesList);
        resMap.put("legend",legendLsit);

        return resMap;
    }

    public List<Prototype> getProtoType(){
        return  scoreMapper.getPrototype();
    }

    public List<Advance> getAdvance(){
        return  scoreMapper.getAdvance();
    }



    public Map getScoreByCustom(){
        Map resMap = new HashMap();
        List<Score> scoreByTimes = scoreMapper.getScoreByCustom();
        List<String > legendLsit = new ArrayList<>();
        List<Series> seriesList = new ArrayList<>();
        scoreByTimes.forEach(score -> {
            legendLsit.add(score.getName());
            Series series = new Series();
            series.setName(score.getName());
            Map<String, String> emphasis = new HashMap<>();
            emphasis.put("focus","series");
            series.setEmphasis(emphasis);
            ArrayList<Float> integers = new ArrayList<>();
            integers.add(score.getAp1());
            integers.add(score.getAp2());
            integers.add(score.getAp3());
            integers.add(score.getAp4());
            integers.add(score.getAp5());
            integers.add(score.getAp6());
            integers.add(score.getAr1());
            integers.add(score.getAr2());
            integers.add(score.getAr3());
            integers.add(score.getAr4());
            integers.add(score.getAr5());
            integers.add(score.getAr6());
            series.setData(integers);
            seriesList.add(series);
        });
        resMap.put("series",seriesList);
        resMap.put("legend",legendLsit);

        return resMap;
    }
}